/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.proxy.component
{
	import mx.messaging.channels.StreamingAMFChannel;
	
	public class ServiceParam
	{
		public var appName:String="";
		private var source:String="";
		private var target:String="";
		private var map:Object;
		private var mapArr:Array;
		private var eql:String="";
		private var spo:SPOParam;
		
		public function ServiceParam()
		{
			mapArr=new Array();
		}
		
		public function set EQL(value:String):void
		{
			spo=null;
			eql=value;
		}
		
		public function set SPO(value:SPOParam):void
		{
			eql="";
			spo=value;
		}
		
		public function setAssociateField(source:String,target:String):void
		{
			this.source=source;
			this.target=target;
		}
		
		public function addMap(mapField:String,targetField:String):void
		{
			map=new Object();
			map["targetField"]=targetField;
			map["mapField"]=mapField;
			mapArr.push(map);
		}
		
		public function toXML():XML
		{
			var sp:XML=new XML(<param appName={appName} />);
			sp.appendChild(<associateField source={source} target={target} />);
			for(var i:int=0;i<mapArr.length;i++)
			{
				sp.appendChild(<map targetField={mapArr[i]["targetField"].toString()}  MapField={mapArr[i]["mapField"].toString()} />);
			}
			if(eql=="")
			{
				sp.appendChild(spo.toXml());
			}
			else
			{
				sp.appendChild(<eql>{eql}</eql>);
			}
			return sp;
		}
		
	}
}